import React, { useState } from 'react';
import { Button, Dropdown, Space, Switch } from 'antd';
import { SettingOutlined, UserOutlined, DashboardOutlined } from '@ant-design/icons';
import { useTranslation } from 'react-i18next';
import type { MenuProps } from 'antd';

interface SystemSettingsProps {
  theme: 'light' | 'dark';
  onThemeChange: (theme: 'light' | 'dark') => void;
}

const SystemSettings: React.FC<SystemSettingsProps> = ({ 
  theme, 
  onThemeChange 
}) => {
  const { t, i18n } = useTranslation();
  const [open, setOpen] = useState(false);

  // 语言切换处理
  const handleLanguageChange = (language: string) => {
    i18n.changeLanguage(language);
  };

  // 主题切换处理
  const handleThemeChange = (checked: boolean) => {
    const newTheme = checked ? 'light' : 'dark';
    onThemeChange(newTheme);
  };

  // 语言菜单项
  const languageItems: MenuProps['items'] = [
    {
      key: 'zh-CN',
      label: '中文',
      onClick: () => handleLanguageChange('zh-CN'),
    },
    {
      key: 'en-US',
      label: 'English',
      onClick: () => handleLanguageChange('en-US'),
    },
  ];

  // 设置菜单项
  const settingsItems: MenuProps['items'] = [
    {
      key: 'language',
      label: (
        <Space>
          <UserOutlined />
          {t('settings.language')}
        </Space>
      ),
      children: languageItems,
    },
    {
      key: 'theme',
      label: (
        <Space>
          <DashboardOutlined />
          {t('settings.theme')}
          <Switch
            size="small"
            checked={theme === 'dark'}
            onChange={handleThemeChange}
          />
        </Space>
      ),
    },
  ];

  return (
    <div className="system-settings">
      <Dropdown
        menu={{ items: settingsItems }}
        placement="bottomRight"
        open={open}
        onOpenChange={setOpen}
        trigger={['click']}
      >
        <Button
          type="text"
          icon={<SettingOutlined />}
          className="settings-button"
        />
      </Dropdown>
    </div>
  );
};

export default SystemSettings; 